// second.js
Page({
  data: {
    text: 'init data',
    check:true,
    num: 0,
    array: [{ text: 'init data' }],
    object: {
      text: 'init data'
    }
  },
  changeText: function () {
    // this.data.text = 'changed data'  // bad, it can not work
    this.setData({
      text: 'changed data'
    })
  },
  changeNum: function () {
    this.data.num = 1
    this.setData({
      num: this.data.num
    })
  },
  changeItemInArray: function () {
    // you can use this way to modify a danamic data path
    this.setData({
      'array[0].text': 'changed data'
    })
  },
  changeItemInObject: function () {
    this.setData({
      'object.text': 'changed data'
    });
  },
  // data里新建一个数据
  addNewField: function () {
    this.setData({
      'newField.text': 'new data'
    })
    console.log(this.data);
  },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return {
      title: '此处可自定义分享标题',
      path: '/pages/second/second'
    }
  },
  onPullDownRefresh: function () {
    // Do something when pull down.
    wx.showModal({
      title: '温馨提示',
      content: '你正在下拉但并没刷新，因为我没做刷新',
      success: function (res) {
        if (wx.canIUse('showModal.cancel')) {
          console.log(res.cancel);
          wx.showModal({
            title: '提示',
            content: '你点击了取消。'
          })
        }
      }
    })
  },
})
